package com.theo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.theo.entity.MaskInfo;
import com.theo.entity.NewsInfo;
import com.theo.service.MaskInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Controller
@RequestMapping("/mask-info")
public class MaskInfoController {

    @Autowired
    private MaskInfoService maskInfoService;

    @RequestMapping("/input.do")
    public String saveMaskInfo(MaskInfo maskInfo) {
        maskInfoService.saveMaskInfo(maskInfo);
        return "redirect:/mask-info/show.do";
    }

    @RequestMapping("/show.do")
    public String showMaskInfo(Model model, @RequestParam(value = "pn", defaultValue = "1") Integer pn) {
        PageHelper.startPage(pn, 8);
        List<MaskInfo> list = maskInfoService.queryAllMaskInfo();
        PageInfo pageInfo = new PageInfo(list, 6);
        model.addAttribute("pageInfo", pageInfo);
        return "admin/mask_list";
    }

    @RequestMapping("/toUpdate.do")
    public String toUpdate(Model model, Integer id) {
        MaskInfo maskInfo = maskInfoService.queryMaskInfoById(id);
        model.addAttribute("mask", maskInfo);
        return "admin/mask_update";
    }

    @RequestMapping("/update.do")
    public String update(MaskInfo maskInfo) {
        maskInfoService.updateMaskInfo(maskInfo);
        return "redirect:/mask-info/show.do";
    }

    @RequestMapping("/delete.do")
    public String deleteMaskInfo(@RequestParam("id") Integer id) {
        maskInfoService.deleteMaskInfo(id);
        return "redirect:/mask-info/show.do";
    }
}

